Page({
    data: {
      history: [],
      // leftColumn: [],
      // rightColumn: [],
      // artworks: [],
    },
  
    onLoad() {
      this.loadHistory();
    },
  
    loadHistory() {
      const history = wx.getStorageSync("historyArtworks") || [];
      console.log("用户浏览过的艺术作品：" + JSON.stringify(history, null, 2));

      // const { leftColumn, rightColumn } = this.data; // 获取当前列
      // let leftCount = leftColumn.length;
      // let rightCount = rightColumn.length;

  
      // 遍历 history，拼接 artistName
      // history.forEach((artwork) => {
      //   // 拼接 artistName
      //   const artistNames = artwork.artArtistBasicInfoRespDtoList
      //       .map(artist => artist.artistName)
      //       .join(' | '); // 用 | 拼接每个 artistName
      //       artwork.artistName = artistNames; // 将拼接的 artistName 添加到 artwork 中

      //       if (leftCount <= rightCount) {
      //           leftColumn.push(artwork);
      //           leftCount++;
      //   } else {
      //       rightColumn.push(artwork);
      //       rightCount++;
      //   }
      // });
  
      // 更新列数据
      // this.setData({ history, leftColumn, rightColumn });


      this.setData({ 
          history: history,
          // artworks:history
        });
    },
  
    goToDetail(e) {
      const artWorkId = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: `/pages/artwork/detail/detail?artWorkId=${artWorkId}`,
      });
    },
  
    clearHistory() {
      wx.showModal({
        title: "Prompt",
        content: "Are you sure you want to clear the history？",
        success: (res) => {
          if (res.confirm) {
            wx.removeStorageSync("historyArtworks");
            this.setData({ 
                history: [],
                leftColumn: [],
                rightColumn: []
             });
            wx.showToast({ title: "Cleared", icon: "success" });
          }
        },
      });
    },
  });
  